package com.example.demo.web;

import com.example.demo.param.dto.collection.InsertCollectionDto;
import com.example.demo.param.vo.CollectionVO;
import com.example.demo.param.vo.FollowUserVO;
import com.example.demo.service.ICollectionService;
import com.example.demo.util.Json;
import io.swagger.annotations.*;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "收藏")
@RestController
@RequestMapping("collection")
public class CollectionController extends BaseController{
    @Autowired private ICollectionService collectionService;

    @ApiOperation("新增收藏")
    @PostMapping("insert")
    public Json<Boolean> insert (@RequestBody InsertCollectionDto dto){
        String uid = this.verification(dto.getToken());
        Boolean exit = this.collectionService.insert(uid,dto.getQuestionId());
        Json<Boolean> json = new Json<>(exit);
        return json;
    }

    @ApiOperation("取消收藏")
    @DeleteMapping("delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "query", dataType = "String")
    })
    public Json<Boolean> delete (@RequestParam String id, @RequestParam String token){
        String uid = this.verification(token);
        Boolean exit = this.collectionService.delete(id);
        Json<Boolean> json = new Json<>(exit);
        return json;
    }

    @ApiOperation("查找我的收藏")
    @GetMapping("get/collection")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "展示的页数", required = true, paramType = "query", dataType = "Integer", example = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页展示几条", required = true, paramType = "query", dataType = "Integer", example = "10"),
})
    public Json<CollectionVO> getMyCollection(@RequestParam String token,
                                 @RequestParam Integer page,
                                 @RequestParam Integer pageSize) {
        String uid = this.verification(token);
        CollectionVO exit = this.collectionService.getMyCollection(uid, page, pageSize);
        Json<CollectionVO> json = new Json<>(exit);
        return json;
    }
}
